package com.cloud.system.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.system.project.model.dto.UserDTO;
import com.cloud.system.project.model.entity.User;
import com.cloud.system.project.model.parm.UserPARM;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 系统用户表 Mapper 接口
 * </p>
 *
 * @author Sam
 * @since 2020-12-27
 */
@Mapper
public interface UserMapper extends BaseMapper<User> {

    /**
     * 分页查询用户信息
     *
     * @param page
     * @param userPARM
     * @return
     */
    IPage<UserDTO> getPage(Page page, @Param("pm") UserPARM userPARM);

    /**
     * 条件查询用户信息
     *
     * @param userPARM
     * @return
     */
    List<UserDTO> getList(UserPARM userPARM);

    /**
     * 单条查询用户信息
     *
     * @param id
     * @return
     */
    UserDTO getByIdEx(String id);

    //update sys_user set status = status - #{num} where id = #{id} and status - {num} > 0
    @Update("update sys_user set status = status - #{num} where id = #{id} ")
    void storeReduce(@Param("id") String id, @Param("num") int num);
}
